package com.github.wxiaoqi.security.auth.interceptor;

import org.springframework.beans.factory.annotation.Autowired;

import com.github.wxiaoqi.security.auth.config.ClientInfoProperties;
import com.github.wxiaoqi.security.auth.service.AuthClientService;

import feign.RequestInterceptor;
import feign.RequestTemplate;

/**
 * Created by ace on 2017/9/12.
 */
public class ClientTokenInterceptor implements RequestInterceptor {
    @Autowired
    private ClientInfoProperties  clientInfoProperties;
    
    @Autowired
    private AuthClientService authClientService;

    @Override
    public void apply(RequestTemplate requestTemplate) {
        try {
            requestTemplate.header(clientInfoProperties.getTokenHeader(), authClientService.apply(clientInfoProperties.getId(), clientInfoProperties.getSecret()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
